package com.jbp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jbp.dao.BlackIpDao;
import com.jbp.model.BlackIp;
import com.jbp.service.BlackIpService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import com.jbp.utils.PageUtils;
import com.jbp.utils.Query;
import java.util.Map;

/**
 * Ip黑名单(BlackIp)表服务实现类
 * @author cc
 * @since 2020-11-06 13:59:23
 */
@Service
public class BlackIpServiceImpl extends ServiceImpl<BlackIpDao, BlackIp> implements BlackIpService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<BlackIp> queryWrapper = new QueryWrapper<>();
        if (params.get("id") != null){
            queryWrapper.like("id",params.get("id"));
        }
        IPage<BlackIp> page = this.page(
                new Query<BlackIp>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public boolean isBlack(String ip) {
        if(StringUtils.isEmpty(ip)) {
            return false;
        }

        BlackIp one = getOne(new QueryWrapper<BlackIp>().eq("ip", ip));

        return one!=null;
    }
}